package com.xiaoyu.im.datamodel.auth;

import com.xiaoyu.base.data.UserData;

import in.srain.cube.util.StringUtil;

import in.srain.cube.request.JsonData;

public class IMTokenInfo {

    public static final IMTokenInfo EMPTY = new IMTokenInfo("", "");

    public final String token;
    public final String vendorUid;

    private IMTokenInfo(String token, String vendorUid) {
        this.token = token;
        this.vendorUid = vendorUid;
    }

    public static IMTokenInfo fromJson(JsonData data) {
        String token = data.optString("token");
        String vendorUid = data.optString("accid"); // Use "vendorUid" if possible
        return StringUtil.isAnyEmpty(token, vendorUid) ? EMPTY : new IMTokenInfo(token, vendorUid);
    }

    public boolean isEmpty() {
        return equals(EMPTY);
    }
}
